//封装策略类
var perfromanceS = function () { }
perfromanceS.prototype.calculate = function (salary) {
    return salary * 4
}

var perfromanceA = function () { }
perfromanceA.prototype.calculate = function (salary) {
    return salary * 3
}

var perfromanceB = function () { }
perfromanceB.prototype.calculate = function (salary) {
    return salary * 2
}

//应用类
var Bonus = function () {
    this.salary = null
    this.strategy = null
}

//设置员工绩效对应策略
Bonus.prototype.setStrategy = function (strategy) {
    this.strategy = strategy
}
//设置原始工资
Bonus.prototype.setSalary = function (salary) {
    this.salary = salary
}
//取得奖金数
Bonus.prototype.getBouns = function (){
    if(!this.strategy){
        throw new Error('未设置strtategy属性')
    }
    return this.strategy.calculate(this.salary)
}

//测试
var bonus = new Bonus()
bonus.setSalary(4000)
bonus.setStrategy(new perfromanceA)
console.log(bonus.getBouns());

bonus.setStrategy(new perfromanceS)
console.log(bonus.getBouns());
